using System.Windows;
using System.Windows.Browser;

namespace MoonRainbow.Input.Mouse
{
    internal class NotIEMouseRightButtonUpBehavior : MouseBehavior
    {
        public NotIEMouseRightButtonUpBehavior()
        {
            HtmlPage.Document.AttachEvent("contextmenu", MouseUp);
        }

        private void MouseUp(object sender, HtmlEventArgs e)
        {
            if (e.MouseButton != MouseButtons.Right) return;
            HtmlPage.Document.Body.RemoveChild(MouseManager.NotIEHuckElement);
            var point = GetPosition(HtmlPage.Plugin.Parent);
            if (point.X > e.ClientX ||
                point.X + Application.Current.Host.Content.ActualWidth < e.ClientX ||
                point.Y > e.ClientY ||
                point.Y + Application.Current.Host.Content.ActualHeight < e.ClientY)
                return;
            e.PreventDefault();
            InvokeMouseEventDetected(new MouseEventDetectedEventArgs(new Point(e.ClientX, e.ClientY)));
        }
    }
}